package com.epower.web.action.epowersentence;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.epower.base.BaseAction;
import com.epower.bo.epower.commons.Result;
import com.epower.bo.epowersentence.EpowerSentenceService;
import com.epower.dataobject.EpowerSentenceDO;

@Scope("prototype")
@Component()
public class EpowerSentenceAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    private int wordid;
    private int id;
    private String spelling;

    private EpowerSentenceService epowerSentenceBO;
    private Result result = Result.succResult();

      
    
    
    public String querySentenceBySpelling(){
        List<TempSentence> tempSentences = new ArrayList<TempSentence>();
        List<EpowerSentenceDO> sentences= epowerSentenceBO.querySentenceBySpelling(spelling);
        for(EpowerSentenceDO sentence:sentences){
            TempSentence temp = new TempSentence();
            temp.setExplain(sentence.getExplains());
            temp.setSentence(sentence.getSentence());
            temp.setId(sentence.getId());
            temp.setSpelling(sentence.getSpelling());
            tempSentences.add(temp);
        }
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("sentences", tempSentences);
        result.setResult(resultMap);
        return SUCCESS;
    }
    
    public String deleteSentenceById(){
        Map<String, Object> resultMap = new HashMap<String, Object>();
        if(epowerSentenceBO.deleteEpowerSentenceById(id)){
            resultMap.put("flag", 1);
        }else{
            resultMap.put("flag", 0);
        }
        result.setResult(resultMap);
        return SUCCESS;
    }
    
    public EpowerSentenceService getEpowerSentenceBO() {
        return epowerSentenceBO;
    }

    public void setEpowerSentenceBO(EpowerSentenceService epowerSentenceBO) {
        this.epowerSentenceBO = epowerSentenceBO;
    }

    public Result getResult() {
        return result;
    }

    public void setResult(Result result) {
        this.result = result;
    }
    
    public int getWordid() {
        return wordid;
    }
    
    public void setWordid(int wordid) {
        this.wordid = wordid;
    }

    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }

    public class TempSentence {

        private int id;

        private String spelling;

        private String sentence;

        private String explain;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

      
        public String getSpelling() {
			return spelling;
		}

		public void setSpelling(String spelling) {
			this.spelling = spelling;
		}

		public String getSentence() {
            return sentence;
        }

        public void setSentence(String sentence) {
            this.sentence = sentence;
        }

        
        public String getExplain() {
            return explain;
        }
        
        public void setExplain(String explain) {
            this.explain = explain;
        }

    }

	public String getSpelling() {
		return spelling;
	}

	public void setSpelling(String spelling) {
		this.spelling = spelling;
	}
    
}
